package com.vehicle.inspection.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.annotation.Nullable
import com.zhida.jiyangcenter.R


/**
 * 输入键盘
 */

class PwdInputMethodView(context: Context, @Nullable attrs: AttributeSet) : LinearLayout(context, attrs), View.OnClickListener {

    private var inputReceiver: InputReceiver? = null

    init {
        LayoutInflater.from(context).inflate(R.layout.view_password_input, this)

        initView()
    }

    private fun initView() {
        findViewById<View>(R.id.btn_1).setOnClickListener(this)
        findViewById<View>(R.id.btn_2).setOnClickListener(this)
        findViewById<View>(R.id.btn_3).setOnClickListener(this)
        findViewById<View>(R.id.btn_4).setOnClickListener(this)
        findViewById<View>(R.id.btn_5).setOnClickListener(this)
        findViewById<View>(R.id.btn_6).setOnClickListener(this)
        findViewById<View>(R.id.btn_7).setOnClickListener(this)
        findViewById<View>(R.id.btn_8).setOnClickListener(this)
        findViewById<View>(R.id.btn_9).setOnClickListener(this)
        findViewById<View>(R.id.btn_0).setOnClickListener(this)
        findViewById<View>(R.id.btn_del).setOnClickListener(this)
    }

    override fun onClick(v: View) {
        val num = v.tag as String
        this.inputReceiver!!.receive(num)
    }


    /**
     * 设置接收器
     * @param receiver
     */
    fun setInputReceiver(receiver: InputReceiver) {
        this.inputReceiver = receiver
    }

    /**
     * 输入接收器
     */
    interface InputReceiver {

        fun receive(num: String)
    }
}